/**
 * 维修记录详情对话框（可用于添加和修改对话框）
 */
var ticketInfoDlg = {
    data: {
        ticketId: "",
        ticketNote: "",
        ticketMoney: "",
        ticketDate: ""
    }
};
var ticket = {
    layerIndex: -1,
    condition: {
        ticketNote: "",
        ticketMoney: "",
        ticketDate: ""
    }
};

/**
 * 放入和获取id选择器的val
 * @type {{setVal: toVal.setVal, getVal: (function(*): (*|void|jQuery))}}
 */
var toParentVal = {
    setVal: function (data , name) {
        laydate.render({
            elem: '#' + name
        });
        $("#"+name , window.parent.document).val(data);
    },
    getVal: function (name) {
        return $("#"+ name , window.parent.document).val();
    }
};

/**
 * 表单验证
 * @returns {*}
 */
ticketInfoDlg.validateForm = function () {
    return true;
};
ticketInfoDlg.close = function () {
    parent.layer.close(window.parent.ticket.layerIndex);
};

/**
 * 点击维修记录按钮
 */
ticket.openTicketCar = function () {
    this.layerIndex = layer.open({
        type: 2,
        title: '添加维修记录',
        area: ['500px', '500'],
        fix: false,
        maxmin: true,
        content: Feng.ctxPath + '/ticket/ticket_edit?ticketId='+toParentVal.getVal("tiId")
    });
};

/**
 * 提交维修记录详情
 */
ticketInfoDlg.addSubmit = function () {

    var ajax = new $ax(Feng.ctxPath + "/ticket/edit", function (data) {
        window.parent.Feng.success("修改成功!");
        toParentVal.setVal(data,"tiId");
        ticketInfoDlg.close();
    }, function (data) {
        window.parent.Feng.error("修改失败!" + data.responseJSON.message + "!");
    });
    this.data.ticketDate = Feng.getLaydate();
    ajax.set(this.data);
    ajax.start();
};



$(function () {
    //注意！vue的model绑定和layui有冲突！
    Feng.initLaydate(ticketInfoDlg.data.ticketDate);
    ticketInfoDlg.app = new Vue({
        el: '#ticketForm',
        data: ticketInfoDlg.data,
        methods: {
            submitForm: function (e) {
                e.preventDefault();
            },
            ensure: function () {
                var result = ticketInfoDlg.validateForm();
                if (result === true) {
                    ticketInfoDlg.addSubmit();
                } else {
                    Feng.alert(result);
                }
            },
            close: function () {
                ticketInfoDlg.close();
            }
        }
    });
    //注意！vue的model绑定和layui有冲突！
    Feng.initLaydate(ticketInfoDlg.data.ticketDate);
});


$(function () {
    //获取车辆信息
    var ajax = new $ax(Feng.ctxPath + "/ticket/getTicketInfo?ticketId=" + toParentVal.getVal("tiId"));
    var result = ajax.start();
    ticketInfoDlg.data = result.data;
    ticketInfoDlg.app = new Vue({
        el: '#ticketForm',
        data: ticketInfoDlg.data,
        methods: {
            submitForm: function (e) {
                e.preventDefault();
            },
            ensure: function () {
                var result = ticketInfoDlg.validateForm();
                if (result === true) {
                } else {
                    Feng.alert(result);
                }
            }
        }
    });
});
